﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraTreeList;
using XCI.Extensions;
using XCI.Windows.Controls;
using XCI.Windows.Helper;

namespace XCI.Windows.Plugin.GridSetting.UI
{
    [ToolboxItem(false)]
    public partial class TreeGeneral : DevExpress.XtraEditors.XtraUserControl
    {
        private TreeSettingPlugin Plugin { get; set; }

        public TreeGeneral()
        {
            InitializeComponent();
            InitializeDescriptionDic();
        }
        /// <summary>
        /// 项目汉化字典
        /// </summary>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        protected static Dictionary<string, string> ItemDescriptionDic { get; set; }
        
        protected void InitializeDescriptionDic()
        {
            if (!DesignMode)
            {
                if (ItemDescriptionDic == null)
                {
                    ItemDescriptionDic = new Dictionary<string, string>();
                    ItemDescriptionDic.Append("Never", "无").Append("Always", "一直显示").Append("Auto", "自动");
                    ItemDescriptionDic.Append("ShowAlways", "一直显示");
                    ItemDescriptionDic.Append("ShowForFocusedRow", "行焦点显示").Append("ShowForFocusedCell", "单元格焦点显示").Append("ShowOnlyInEditor", "仅激活编辑器显示");
                    ItemDescriptionDic.Append("MouseDown", "鼠标按下").Append("MouseUp", "鼠标起来").Append("Click", "单击").Append("MouseDownFocused", "鼠标按下并焦点");
                }
                
                WinHelper.AddEnum(boxTreeLineStyle, typeof(LineStyle), ItemDescriptionDic);
                WinHelper.AddEnum(boxShowButtonMode, typeof(ShowButtonModeEnum), ItemDescriptionDic);
                WinHelper.AddEnum(boxHorzScrollVisibility, typeof(ScrollVisibility), ItemDescriptionDic);
                WinHelper.AddEnum(boxVertScrollVisibility, typeof(ScrollVisibility), ItemDescriptionDic);
            }
        }

        public void Initialize(TreeSettingPlugin uiplugin)
        {
            this.Plugin = uiplugin;
            WinHelper.BindCustomPropertyControlValue(panelControl1, Plugin.Tree);
            btnCleanSort.Enabled   = Plugin.Tree.SortedColumnCount > 0;
            btnCleanFilter.Enabled = Plugin.Tree.ActiveFilter.Count > 0;
        }
        
        private void btnCleanSort_Click(object sender, EventArgs e)
        {
            if (MessageBoxHelper.ShowWarnYesNo("确定要清除列排序吗？") == DialogResult.Yes)
            {
                Plugin.Tree.ClearSorting();
                btnCleanSort.Enabled = false;
            }
        }
        
        private void btnCleanFilter_Click(object sender, EventArgs e)
        {
            if (MessageBoxHelper.ShowWarnYesNo("确定要清除列过滤吗？") == DialogResult.Yes)
            {
                Plugin.Tree.ClearColumnsFilter();
                btnCleanFilter.Enabled = false;
            }
        }
    }
}
